// ==UserScript==
// @name           etree on LMA
// @namespace      http://code.google.com/p/etree-on-lma/
// @include        http://www.archive.org/details/*    
// ==/UserScript==


if (location.href.match(/\.(?!0)\d+\./)) {
   addJQuery(linkEtree);
}

function linkEtree() {
   shnStr = location.href.match(/\.(?!0)\d+\./);
   shnId = shnStr[0].match(/\d+/);
   appendLink = '<a target="_dbe" href="http://db.etree.org/shn/' + shnId[0] + '"><img style="width:16px;height:16px;vertical-align:middle" src="%3D%3D" border="0" title="Link to db.etree.org Record" /></a> shnid: <a target="_dbe" href="http://db.etree.org/shn/' + shnId[0] + '">'+ shnId[0] +'</a><br />';
   $("h1:contains('Resources')").closest('div').append(appendLink);
}

function addJQuery(callback) {
  var script = document.createElement("script");
  script.setAttribute("src", "http://code.jquery.com/jquery-1.4.2.min.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "(" + callback.toString() + ")();";
    document.body.appendChild(script);
  }, false);
  document.body.appendChild(script);
}

